package cn.tangsihai.mq._04_direct;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Producer {
    // 交换机名
    public static final String EXCHANGE_DIRECT_NAME = "EXCHANGE_DIRECT_NAME11";
    public static void main(String[] args) throws Exception{
        // 创建连接
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("115.159.88.63");
        Connection connection = factory.newConnection();
        // 创建通道
        Channel channel = connection.createChannel();
        // 创建交换机
        channel.exchangeDeclare(EXCHANGE_DIRECT_NAME, BuiltinExchangeType.DIRECT);
        // 发送消息
        channel.basicPublish(EXCHANGE_DIRECT_NAME, "info", null, "汤思海发送info消息".getBytes());
        channel.basicPublish(EXCHANGE_DIRECT_NAME, "error", null, "汤思海发送error消息".getBytes());
        System.out.println("消息发送成功");
    }
}
